package a66weding.com.jiehuntong.activity.me;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.application.GlobalApplication;
import a66weding.com.jiehuntong.beans.MeInvoiceMessageBean;
import a66weding.com.jiehuntong.common.utils.CUtils;

/**
 * 这是我的界面下发票信息的界面
 * Created by Administrator on 2016/7/29.
 */
public class MeInvoiceMessageActivity extends MeBaseActivity  implements View.OnClickListener {
    private LinearLayout mBackLay;
    private LinearLayout mShow1Lay;
    private LinearLayout mShow2Lay;
    private LinearLayout mShow3Lay;
    private LinearLayout mInvoiceLay;
    private ScrollView mInvoiceSv;
    private TextView mBackContentTv;
    private TextView mHeaderTitleTv;
    private TextView mRightTitleTv;
    private ImageView mNo1Iv;
    private ImageView mNo2Iv;
    private ImageView mNo3Iv;
    private ImageView mShow1Iv;
    private ImageView mShow2Iv;
    private ImageView mShow3Iv;
    private Button mCommitBt;
    private EditText mInvoiceEt,mInvoice1Et, mInvoice2Et,mInvoice3Et,mInvoice4Et,
            mInvoice5Et,mInvoice6Et,mInvoice7Et,mInvoice8Et,mInvoice9Et,mInvoice10Et;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_me_invoice_message);
        ((GlobalApplication) getApplication()).getActivityManager().addActivity("MeInvoiceMessageActivity", this);

        initview();
    }

    private void initview() {
        mBackLay = (LinearLayout) findViewById(R.id.lay_head_backlay);
        mShow1Lay = (LinearLayout) findViewById(R.id.ll_me_show_1);
        mShow2Lay = (LinearLayout) findViewById(R.id.ll_me_show_2);
        mShow3Lay = (LinearLayout) findViewById(R.id.ll_me_show_3);
        mInvoiceLay = (LinearLayout) findViewById(R.id.ll_me_invoice);
        mBackContentTv = (TextView) findViewById(R.id.headleft_title_tv);
        mHeaderTitleTv = (TextView) findViewById(R.id.headcenter_title_tv);
        mRightTitleTv = (TextView) findViewById(R.id.headright_title_tv);
        mNo1Iv = (ImageView) findViewById(R.id.iv_me_no_1);
        mNo2Iv = (ImageView) findViewById(R.id.iv_me_no_2);
        mNo3Iv = (ImageView) findViewById(R.id.iv_me_no_3);
        mShow1Iv = (ImageView) findViewById(R.id.iv_me_show_1);
        mShow2Iv = (ImageView) findViewById(R.id.iv_me_show_2);
        mShow3Iv = (ImageView) findViewById(R.id.iv_me_show_3);
        mInvoiceSv = (ScrollView) findViewById(R.id.sl_me_invoice);
        mCommitBt = (Button) findViewById(R.id.btn_add);
        mInvoiceEt = (EditText) findViewById(R.id.et_me_set_invoice);
        mInvoice1Et = (EditText) findViewById(R.id.et_me_set_invoice_1);
        mInvoice2Et = (EditText) findViewById(R.id.et_me_set_invoice_2);
        mInvoice3Et = (EditText) findViewById(R.id.et_me_set_invoice_3);
        mInvoice4Et = (EditText) findViewById(R.id.et_me_set_invoice_4);
        mInvoice5Et = (EditText) findViewById(R.id.et_me_set_invoice_5);
        mInvoice6Et = (EditText) findViewById(R.id.et_me_set_invoice_6);
        mInvoice7Et = (EditText) findViewById(R.id.et_me_set_invoice_7);
        mInvoice8Et = (EditText) findViewById(R.id.et_me_set_invoice_8);
        mInvoice9Et = (EditText) findViewById(R.id.et_me_set_invoice_9);
        mInvoice10Et = (EditText) findViewById(R.id.et_me_set_invoice_10);

        mBackContentTv.setText("订单");
        mHeaderTitleTv.setText("发票信息");
        mRightTitleTv.setVisibility(View.GONE);

        mBackLay.setOnClickListener(this);
        mShow1Lay.setOnClickListener(this);
        mShow2Lay.setOnClickListener(this);
        mShow3Lay.setOnClickListener(this);
        mCommitBt.setOnClickListener(this);

        if (MeInvoiceMessageBean.getMeInvoice() != null){
            mInvoiceEt.setText(MeInvoiceMessageBean.getMeInvoice());
        }  if(MeInvoiceMessageBean.getMeInvoice1() != null){
            mInvoice1Et.setText(MeInvoiceMessageBean.getMeInvoice1());
        }  if(MeInvoiceMessageBean.getMeInvoice2() != null){
            mInvoice2Et.setText(MeInvoiceMessageBean.getMeInvoice2());
        }  if(MeInvoiceMessageBean.getMeInvoice3() != null){
            mInvoice3Et.setText(MeInvoiceMessageBean.getMeInvoice3());
        }  if(MeInvoiceMessageBean.getMeInvoice4() != null){
            mInvoice4Et.setText(MeInvoiceMessageBean.getMeInvoice4());
        }  if(MeInvoiceMessageBean.getMeInvoice5() != null){
            mInvoice5Et.setText(MeInvoiceMessageBean.getMeInvoice5());
        }  if(MeInvoiceMessageBean.getMeInvoice6() != null){
            mInvoice6Et.setText(MeInvoiceMessageBean.getMeInvoice6());
        }  if(MeInvoiceMessageBean.getMeInvoice7() != null){
            mInvoice7Et.setText(MeInvoiceMessageBean.getMeInvoice7());
        }  if(MeInvoiceMessageBean.getMeInvoice8() != null){
            mInvoice8Et.setText(MeInvoiceMessageBean.getMeInvoice8());
        }  if(MeInvoiceMessageBean.getMeInvoice9() != null){
            mInvoice9Et.setText(MeInvoiceMessageBean.getMeInvoice9());
        }  if(MeInvoiceMessageBean.getMeInvoice10() != null){
            mInvoice10Et.setText(MeInvoiceMessageBean.getMeInvoice10());
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.lay_head_backlay: //点击订单，返回到上一级界面
                finish();

                break;
            case R.id.ll_me_show_1: //点击不开发票
                mNo1Iv.setVisibility(View.GONE);
                mNo2Iv.setVisibility(View.VISIBLE);
                mNo3Iv.setVisibility(View.VISIBLE);
                mShow1Iv.setVisibility(View.VISIBLE);
                mShow2Iv.setVisibility(View.GONE);
                mShow3Iv.setVisibility(View.GONE);
                mInvoiceLay.setVisibility(View.GONE);
                mInvoiceSv.setVisibility(View.GONE);

                break;
            case R.id.ll_me_show_2: //点击普通发票
                mNo1Iv.setVisibility(View.VISIBLE);
                mNo2Iv.setVisibility(View.GONE);
                mNo3Iv.setVisibility(View.VISIBLE);
                mShow1Iv.setVisibility(View.GONE);
                mShow2Iv.setVisibility(View.VISIBLE);
                mShow3Iv.setVisibility(View.GONE);
                mInvoiceLay.setVisibility(View.VISIBLE);
                mInvoiceSv.setVisibility(View.GONE);

                break;
            case R.id.ll_me_show_3: //点击增值税发票
                mNo1Iv.setVisibility(View.VISIBLE);
                mNo2Iv.setVisibility(View.VISIBLE);
                mNo3Iv.setVisibility(View.GONE);
                mShow1Iv.setVisibility(View.GONE);
                mShow2Iv.setVisibility(View.GONE);
                mShow3Iv.setVisibility(View.VISIBLE);
                mInvoiceLay.setVisibility(View.GONE);
                mInvoiceSv.setVisibility(View.VISIBLE);

                break;
            case R.id.btn_add: //点击增值税发票
                int show1 = mShow1Iv.getVisibility();
                int show2 = mShow2Iv.getVisibility();
                int show3 = mShow3Iv.getVisibility();
                if (show1 == 0){            //不开发票
                    MyInvoiceEvent event = new MyInvoiceEvent("不开发票",0,0,"");
                    EventBus.getDefault().post(event);
                    finish();
                    return;
                } else if (show2 == 0) {    // 普通发票
                    String invoice = mInvoiceEt.getText().toString().trim();
                    if (TextUtils.isEmpty(invoice)){
                        CUtils.showToast("发票内容不能为空");
                        return;
                    } else {
                        MyInvoiceEvent event = new MyInvoiceEvent(invoice,1,0,invoice);

                        EventBus.getDefault().post(event);
                        // 向订单发票信息里设置普通发票内容
                        MeInvoiceMessageBean.setMeInvoice(invoice);
                        finish();
                        return;
                    }
                } else {// 增值税发票
                    String invoice1 = mInvoice1Et.getText().toString().trim();
                    String invoice2 = mInvoice2Et.getText().toString().trim();
                    String invoice3 = mInvoice3Et.getText().toString().trim();
                    String invoice4 = mInvoice4Et.getText().toString().trim();
                    String invoice5 = mInvoice5Et.getText().toString().trim();
                    String invoice6 = mInvoice6Et.getText().toString().trim();
                    String invoice7 = mInvoice7Et.getText().toString().trim();
                    String invoice8 = mInvoice8Et.getText().toString().trim();
                    String invoice9 = mInvoice9Et.getText().toString().trim();
                    String invoice10 = mInvoice10Et.getText().toString().trim();
                    if (TextUtils.isEmpty(invoice1)) {
                        CUtils.showToast("公司名称不能为空");
                        return;
                    } else if (TextUtils.isEmpty(invoice2)) {
                        CUtils.showToast("纳税人识别码不能为空");
                        return;
                    } else if (TextUtils.isEmpty(invoice3)) {
                        CUtils.showToast("注册地址不能为空");
                        return;
                    }
                    else if (TextUtils.isEmpty(invoice4)) {
                        CUtils.showToast("注册电话不能为空");
                        return;
                    } else if (TextUtils.isEmpty(invoice5)) {
                        CUtils.showToast("开户银行不能为空");
                        return;
                    } else if (TextUtils.isEmpty(invoice6)) {
                        CUtils.showToast("银行账号不能为空");
                        return;
                    } else if (TextUtils.isEmpty(invoice7)) {
                        CUtils.showToast("发票内容不能为空");
                        return;
                    } else if (TextUtils.isEmpty(invoice8)) {
                        CUtils.showToast("收票人姓名不能为空");
                        return;
                    } else if (TextUtils.isEmpty(invoice9)) {
                        CUtils.showToast("收票人手机不能为空");
                        return;
                    } else if (TextUtils.isEmpty(invoice10)) {
                        CUtils.showToast("收票人地址不能为空");
                        return;
                    } else {


                        MyInvoiceEvent event = new MyInvoiceEvent(invoice7,1,1,invoice1);
                        event.setInvoce(2);
                        event.setInvocetype(1);
                        event.setInvoiceTitle(invoice1);

                        event.setNvc_name2(invoice2);
                        event.setNvc_name3(invoice3);
                        event.setNvc_name4(invoice4);
                        event.setNvc_name5(invoice5);
                        event.setNvc_name6(invoice6);

                        event.setNvc_name7(invoice8);
                        event.setNvc_name8(invoice9);
                        event.setNvc_name9(invoice10);
                        EventBus.getDefault().post(event);

                        // 向订单发票信息里设置增值税发票内容
                        MeInvoiceMessageBean.setMeInvoice1(invoice1);
                        MeInvoiceMessageBean.setMeInvoice2(invoice2);
                        MeInvoiceMessageBean.setMeInvoice3(invoice3);
                        MeInvoiceMessageBean.setMeInvoice4(invoice4);
                        MeInvoiceMessageBean.setMeInvoice5(invoice5);
                        MeInvoiceMessageBean.setMeInvoice6(invoice6);
                        MeInvoiceMessageBean.setMeInvoice7(invoice7);
                        MeInvoiceMessageBean.setMeInvoice8(invoice8);
                        MeInvoiceMessageBean.setMeInvoice9(invoice9);
                        MeInvoiceMessageBean.setMeInvoice10(invoice10);
                        // 关闭界面
                        finish();
                    }
                }

                break;
        }
    }

    class MyInvoiceEvent{
        String invoice;
        private int invoce;
        private int invocetype;
        private String invoiceTitle;

        private String nvc_name2;             //纳税人识别码
        private String nvc_name3;             //注册地址
        private String nvc_name4;             //注册电话
        private String nvc_name5;             //开户银行
        private String nvc_name6;             //银行账户
        private String nvc_name7;             //收票人姓名
        private String nvc_name8;             //收票人手机
        private String nvc_name9;             //收票人地址




        public MyInvoiceEvent(String invoice, int invoce, int invocetype, String invoiceTitle) {
            this.invoice = invoice;
            this.invoce = invoce;
            this.invocetype = invocetype;
            this.invoiceTitle = invoiceTitle;
        }

        public String getInvoice() {
            return invoice;
        }

        public void setInvoice(String invoice) {
            this.invoice = invoice;
        }

        public int getInvoce() {
            return invoce;
        }

        public void setInvoce(int invoce) {
            this.invoce = invoce;
        }

        public int getInvocetype() {
            return invocetype;
        }

        public void setInvocetype(int invocetype) {
            this.invocetype = invocetype;
        }

        public String getInvoiceTitle() {
            return invoiceTitle;
        }

        public void setInvoiceTitle(String invoiceTitle) {
            this.invoiceTitle = invoiceTitle;
        }

        public String getNvc_name2() {
            return nvc_name2;
        }

        public void setNvc_name2(String nvc_name2) {
            this.nvc_name2 = nvc_name2;
        }

        public String getNvc_name3() {
            return nvc_name3;
        }

        public void setNvc_name3(String nvc_name3) {
            this.nvc_name3 = nvc_name3;
        }

        public String getNvc_name4() {
            return nvc_name4;
        }

        public void setNvc_name4(String nvc_name4) {
            this.nvc_name4 = nvc_name4;
        }

        public String getNvc_name5() {
            return nvc_name5;
        }

        public void setNvc_name5(String nvc_name5) {
            this.nvc_name5 = nvc_name5;
        }

        public String getNvc_name6() {
            return nvc_name6;
        }

        public void setNvc_name6(String nvc_name6) {
            this.nvc_name6 = nvc_name6;
        }

        public String getNvc_name7() {
            return nvc_name7;
        }

        public void setNvc_name7(String nvc_name7) {
            this.nvc_name7 = nvc_name7;
        }

        public String getNvc_name8() {
            return nvc_name8;
        }

        public void setNvc_name8(String nvc_name8) {
            this.nvc_name8 = nvc_name8;
        }

        public String getNvc_name9() {
            return nvc_name9;
        }

        public void setNvc_name9(String nvc_name9) {
            this.nvc_name9 = nvc_name9;
        }

        @Override
        public String toString() {
            return "MyInvoiceEvent{" +
                    "invoice='" + invoice + '\'' +
                    ", invoce=" + invoce +
                    ", invocetype=" + invocetype +
                    ", invoiceTitle='" + invoiceTitle + '\'' +
                    ", nvc_name2='" + nvc_name2 + '\'' +
                    ", nvc_name3='" + nvc_name3 + '\'' +
                    ", nvc_name4='" + nvc_name4 + '\'' +
                    ", nvc_name5='" + nvc_name5 + '\'' +
                    ", nvc_name6='" + nvc_name6 + '\'' +
                    ", nvc_name7='" + nvc_name7 + '\'' +
                    ", nvc_name8='" + nvc_name8 + '\'' +
                    ", nvc_name9='" + nvc_name9 + '\'' +
                    '}';
        }
    }

}
